//
//  BKOrderPaymentCell.m
//  bestkeep
//
//  Created by 马乾征 on 16/11/11.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKOrderPaymentCell.h"
#import "BK_OD_Color.h"
/**
    基类
 */
@implementation BKOrderPaymentCell

- (void)fillData:(id)data{}
+ (CGFloat)computeHeight:(id)data{
    return 0;
}

@end

/**
    账户余额
 */
@implementation BKOrderAccountBlancePaymentCell
{
    UILabel *_accountBlanceText;
    UILabel *_accountBlanceMoney;
    UIImageView *_selected;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setSeparatorInset:UIEdgeInsetsMake(0, ApplicationBackGauge, 0, 0)];
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    _accountBlanceText = [[UILabel alloc] init];
    _accountBlanceText.backgroundColor = [UIColor clearColor];
    _accountBlanceText.textColor = kOrderBlack1;
    _accountBlanceText.font = UIFontCustom(15);
    [self.contentView addSubview:_accountBlanceText];
    
    _accountBlanceMoney = [[UILabel alloc] init];
    _accountBlanceMoney.backgroundColor = [UIColor clearColor];
    _accountBlanceMoney.textColor = kOrderBlack1;
    _accountBlanceMoney.font = UIFontCustom(15);
    [self.contentView addSubview:_accountBlanceMoney];
    
    _selected = [[UIImageView alloc] init];
    [self.contentView addSubview:_selected];
    
    [self makeConstraints];
}

- (void)makeConstraints
{
    [_accountBlanceText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ApplicationBackGauge);
        make.centerY.mas_equalTo(self);
    }];
    
    [_accountBlanceMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_accountBlanceText.mas_right).offset(10);
        make.centerY.mas_equalTo(self);
    }];
    
    [_selected mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-ApplicationBackGauge);
        make.centerY.mas_equalTo(self);
    }];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (selected)
    {
        _selected.image = [UIImage imageNamed:@"BKOrder_selected.png"];
    }
    else
    {
        _selected.image = [UIImage imageNamed:@"BKOrder_unselected.png"];
    }

}

- (void)fillData:(id)data
{
    if (data) {
        BKODPaymentAccount *account = data;
        _selected.image = [UIImage imageNamed:@"BKOrder_unselected.png"];
        _accountBlanceText.text = account.account_type_name;
        _accountBlanceMoney.text = [NSString stringWithFormat:@"￥%@",account.account_balance];
    }
}

+(CGFloat)computeHeight:(id)data{
    return 40;
}
@end

/**
    其他支付方式
 */
@implementation BKOrderOtherPaymentCell
{
    UILabel *_paymentName;
    UIImageView *_paymentIcon;
    UIImageView *_selected;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setSeparatorInset:UIEdgeInsetsMake(0, ApplicationBackGauge, 0, 0)];
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    _paymentIcon = [[UIImageView alloc] init];
    [self.contentView addSubview:_paymentIcon];
    
    _paymentName = [[UILabel alloc] init];
    _paymentName.backgroundColor = [UIColor clearColor];
    _paymentName.textColor = kOrderBlack1;
    _paymentName.font = UIFontCustom(15);
    [self.contentView addSubview:_paymentName];
    
    _selected = [[UIImageView alloc] init];
    [self.contentView addSubview:_selected];
    
    [self makeConstraints];
}

- (void)makeConstraints
{
    [_paymentIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ApplicationBackGauge);
        make.centerY.mas_equalTo(self);
    }];
    
    [_paymentName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_paymentIcon.mas_right).offset(10);
        make.centerY.mas_equalTo(self);
    }];
    
    [_selected mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-ApplicationBackGauge);
        make.centerY.mas_equalTo(self);
    }];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (selected)
    {
        _selected.image = [UIImage imageNamed:@"BKOrder_selected.png"];
    }
    else
    {
        _selected.image = [UIImage imageNamed:@"BKOrder_unselected.png"];
    }
    
}

- (void)fillData:(id)data
{
    if (!data) {
        return;
    }
    
    NSString *titile;
    NSString *imageName;
    if ([data isEqualToString:@"isAliPay"]) {
        titile = kOrderLocalizeString(@"BKOrderAliPay");//支付宝支付
        imageName = @"BKOrder_alipay";
    }
    if ([data isEqualToString:@"isWXPay"]) {
        titile = kOrderLocalizeString(@"BKOrderWXPay");//微信支付
        imageName = @"BKOrder_WeChat";
    }
    _paymentName.text = titile;
    _paymentIcon.image = [UIImage imageNamed:imageName];
    _selected.image = [UIImage imageNamed:@"BKOrder_unselected.png"];
}

+ (CGFloat)computeHeight:(id)data{
//    return 40;
    return 45;
}
@end
